package com.newbsd.web.maventest.dao;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

import org.apache.commons.dbutils.DbUtils;


/**
 * 
 * @author 张成玉 dao层数据库登录
 *
 */

public class ConnectDb {

	public static Connection Connect() {
		Connection conn = null;
		try {
			/**
			 * 张成玉 在程序中访问数据源
			 */
			DbUtils.loadDriver("com.mysql.jdbc.Driver");
			Context context = new InitialContext();
			DataSource datasource = (DataSource)context.lookup("java:comp/env/jdbc/maventest");
			conn = datasource.getConnection();
		} catch (NamingException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}
}
